package com.xblibo.xruth.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.mlw.vlh.ValueList;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.xblibo.xruth.common.BaseController;
import com.xblibo.xruth.entity.User;
import com.xblibo.xruth.service.UserService;


/**
 * @Title: PersonnelController.java
 * @Package com.xblibo.xruth.controller
 * @Description TODO(添加描述)
 * @author xblibo
 * @date 2011-07-15 15:40:06
 * @version V1.0
 */

@Controller
public class PersonnelController extends BaseController{

	@Resource(name="userService")
	private UserService userService;

	@RequestMapping(value = "/personnel/list")
	public String list(HttpServletRequest request){
		params.put("companyId",getCurrentUser().getCompanyId());
		ValueList   valueList  =  getValueList("user_list", params, request);
		request.setAttribute("valueList", valueList);
		System.out.println(valueList.getList());
		return "/personnel/personnel_list";
	}
	
	@RequestMapping(value = "/personnel/add", method = RequestMethod.GET)
	public String add(){
		return "/personnel/personnel_add";
	}
	
	@RequestMapping(value = "/personnel/add", method = RequestMethod.POST)
	public String save(User user){
		user.setCompanyId(getCurrentUser().getCompanyId());
		user.setCompanyName(getCurrentUser().getCompanyName());
		userService.saveOrUpdate(user);
		return "redirect:/personnel/list";
	}
	
	@RequestMapping(value = "/personnel/modify",method = RequestMethod.GET)
	public String modify(Integer id,ModelMap map){
		User personnel = userService.findById(id);
		map.addAttribute("personnel",personnel);
		return "/personnel/personnel_modify";
	}
	
	@RequestMapping(value = "/personnel/modify",method = RequestMethod.POST)
	public String update(User user){
		userService.saveOrUpdate(user);
		return "redirect:/personnel/list";
	}

	@RequestMapping(value = "/personnel/detail")
	public String detail(Integer id,ModelMap map){
		User personnel = userService.findById(id);
		map.addAttribute("personnel",personnel);
		return "/personnel/personnel_detail";
	}
	
	@RequestMapping(value = "/personnel/delete")
	public String delete(Integer id){
		userService.delete(id);
		return "redirect:/personnel/list";
	}
	
	@RequestMapping(value = "/personnel/index")
	public String index(Integer id){
		return "redirect:/personnel/list";
	}

}
